<template>
	<view class="deviceadd">
		<view class="title">设备ID</view>
		<view class="content">
			<input type="text" placeholder="请输入您的设备ID" v-model="deviceid" />
		</view>
		<button type="primary" @click="bindFun()">绑定</button>
	</view>
</template>

<script>
	import { devicebindscan } from '../../api/index.js'
	export default {
		data() {
			return {
				deviceid:''
			}
		},
		onLoad:function(data){
			if(data.id){
				this.deviceid = data.id
			}
		},
		methods: {
			bindFun:function(){
				if(!this.deviceid){
					uni.showToast({
						icon:'none',
						title:"请输入设备ID号"
					})
				}else{
					devicebindscan({
						info: this.deviceid
					}).then((res) => {
						console.log(res)
						if(res.code == 0){
							uni.showModal({
								title:'提示',
								content:res.data.text,
								complete:function(){
									uni.redirectTo({
										url:'../devicemanage/devicemanage'
									})
								}
							})
						}else{
							uni.showToast({
								icon:'none',
								title:res.msg
							})
						}
					}).catch((e) => {
						console.log(e);
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.deviceadd{
		padding: 0 60rpx;
		border-top: 1rpx solid $uni-solid-color;
		.title{
			margin-top: 90rpx;
			font-weight: bold;
			font-size: 56rpx;
		}
		.content{
			margin-top: 90rpx;
			border-bottom: 1rpx solid $uni-solid-color;
			input{
				padding-bottom: 15rpx;
			}
		}
		button{
			margin-top: 60rpx;
		}
	}
</style>
